package javasec.contempt.consoles;

import java.io.InputStream;
import java.io.OutputStream;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

public class SeedLogConsole extends MessageConsole implements Runnable
{
	private MessageConsoleStream outMessageStream=null;
	private InputStream seedLogInput=null;
	
	public SeedLogConsole(String name, ImageDescriptor imageDescriptor)
	{
		super(name, imageDescriptor);
		outMessageStream=newMessageStream();
	}

	public void setStream(InputStream is)
	{
		seedLogInput=is;
		new Thread(this).start();
	}
	
	public void run()
	{
		if(seedLogInput==null)return;
		if(outMessageStream==null)return;
		
		byte[] buffer=new byte[20];
		int length;
		
		try
		{
			while(-1!=(length=seedLogInput.read(buffer)))
			{
				outMessageStream.print(new String(buffer,0,length));
			}
		}
		catch(Exception e)
		{
			return;
		}
	}
}
